package cqrtplm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ty.basic.response.ResponseResult;
import cqrtplm.constant.RouteConstant;
import cqrtplm.entity.RtCertFiledPartinfoDO;
import cqrtplm.service.RtCertFiledPartinfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 零部件信息控制器
 */
@RestController
@Api(tags = "认证-零部件信息")
@RequestMapping("/rest"+RouteConstant.RATO + "cert/partinfo/" + "v1")
public class RtCertFiledPartinfoController {

    @Autowired
    private RtCertFiledPartinfoService rtCertFiledPartinfoService;

    /**
     * 查询零部件信息列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "list", notes = "获取零部件信息列表")
    public ResponseResult list(@RequestBody RtCertFiledPartinfoDO rtCertFiledPartinfo) {
        List<RtCertFiledPartinfoDO> list = rtCertFiledPartinfoService.selectRtCertFiledPartinfoList(rtCertFiledPartinfo);
        return ResponseResult.success(list);
    }

    /**
     * 分页查询零部件信息列表
     */
    @PostMapping("/pagelist")
    @ApiOperation(value = "pagelist", notes = "分页获取零部件信息列表")
    public ResponseResult<PageInfo<RtCertFiledPartinfoDO>> pagelist(
            @RequestBody RtCertFiledPartinfoDO rtCertFiledPartinfo,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "100") int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<RtCertFiledPartinfoDO> list = rtCertFiledPartinfoService.selectRtCertFiledPartinfoList(rtCertFiledPartinfo);
        PageInfo<RtCertFiledPartinfoDO> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }

    /**
     * 导出零部件信息列表
     */
    @PostMapping("/export")
    @ApiOperation(value = "export", notes = "导出零部件信息列表")
    public void export(HttpServletResponse response, RtCertFiledPartinfoDO rtCertFiledPartinfo) {
        List<RtCertFiledPartinfoDO> list = rtCertFiledPartinfoService.selectRtCertFiledPartinfoList(rtCertFiledPartinfo);
        // ExcelUtil.listToExcel(list, RtCertFiledPartinfoDO.class, wwb, "零部件信息数据");
    }

    /**
     * 获取零部件信息详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "getInfo", notes = "获取零部件信息详情")
    public ResponseResult getInfo(@PathVariable("id") String id) {
        return ResponseResult.success(rtCertFiledPartinfoService.selectRtCertFiledPartinfoById(id));
    }

    /**
     * 新增零部件信息
     */
    @PostMapping("/add")
    @ApiOperation(value = "add", notes = "新增零部件信息")
    public ResponseResult add(@RequestBody RtCertFiledPartinfoDO rtCertFiledPartinfo) {
        return ResponseResult.success(rtCertFiledPartinfoService.insertRtCertFiledPartinfo(rtCertFiledPartinfo));
    }

    /**
     * 修改零部件信息
     */
    @PostMapping("/edit")
    @ApiOperation(value = "edit", notes = "修改零部件信息")
    public ResponseResult edit(@RequestBody RtCertFiledPartinfoDO rtCertFiledPartinfo) {
        return ResponseResult.success(rtCertFiledPartinfoService.updateRtCertFiledPartinfo(rtCertFiledPartinfo,null));
    }

    /**
     * 删除零部件信息
     */
    @DeleteMapping("/del")
    @ApiOperation(value = "delete", notes = "删除零部件信息")
    public ResponseResult remove(@RequestBody List<String> ids) {
        return ResponseResult.success(rtCertFiledPartinfoService.deleteRtCertFiledPartinfoByIds(ids));
    }

    @GetMapping(value = "/getparttype")
    @ApiOperation(value = "getPartType", notes = "获取零部件信息详情")
    public ResponseResult getPartType() {
        return ResponseResult.success(rtCertFiledPartinfoService.getPartTypeList());
    }

}